home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 90 / CD Actual 90.iso / Software3D / PovLab / povlab / PLUGINS / PLUGLIB.ZIP / GATEWAY.C next >
Encoding:
C/C++ Source or Header  |  1996-03-27  |  6.1 KB  |  203 lines

  1. // ----------------------------------------------------------------------------
  2. // --
  3. // --  Ce source est livré tel quel, les modifications encourues étant sous
  4. // --  la responsabilité du programmeur effectuant ces dernières.
  5. // --  Respecter le format, afin que la lisibilité soit conforme et homogène.
  6. // --  Si vous pensez avoir réalisé des amélioration, contactez :
  7. // --
  8. // --                        C H R O M A G R A P H I C S
  9. // --                        D E N I S     O L I V I E R
  10. // --                        5,  boulevard  Franck  Lamy
  11. // --                        1 7 2 0 0     R  O  Y  A  N
  12. // --                        F    R    A     N    C    E
  13. // --                        ───────────────────────────
  14. // --                        T é l :  4 6  0 5  4 9  4 4
  15. // --                        F a x :  4 6  0 5  6 7  4 3
  16. // --
  17. // --   Compiled and linked under :
  18. // --
  19. // --   *  Watcom 10.a 32 C/C++ : wcl ... (no options)
  20. // --   *  Borland C/C++ 3.1    : bcc ... (no options)
  21. // --
  22. // ----------------------------------------------------------------------------
  23.  
  24. #include <STDIO.H>
  25. #if __WATCOMC__
  26.   #include <I86.H>
  27. #else
  28.   #include <DOS.H>
  29. #endif
  30. #include <STRING.H>
  31. #include <CONIO.H>
  32. #include <STDLIB.H>
  33. #include <FLOAT.H>
  34. #include <MATH.H>
  35. #include <IO.H>
  36.  
  37. // ----------------------- Here is included the PLUGINS C and H files
  38.  
  39. #include "PLUGINS.H"
  40. #include "PLUGINS.C"
  41.  
  42. typedef struct {
  43.   double Long;
  44.   double Angle;
  45.   double X,Y;
  46. } CYL;
  47.  
  48. #define PI 3.14159265358979323846264338327950288419716939937511
  49.  
  50. // ---------------------------------------------------------------------------
  51. // -- DATA SCRIPT FOR POVLAB -------------------------------------------------
  52. // ---------------------------------------------------------------------------
  53. int out_data_interface(void) {
  54.   FILE *File;
  55.  
  56.   // ------------- Don't forget to name the .PLG like the .EXE
  57.   // ------------- file you're running |-) !
  58.   // ------------- The command line parameters are returned in the
  59.   // ------------- Order you generate the graphic datas.
  60.  
  61.   if (!(File=fopen("GATEWAY.PLG","wt"))) return 0;
  62.  
  63.   fprintf(File,"TITLE: GATEWAY_FORM_2D_1.0\n");
  64.   fprintf(File,"MESSAGE: Copyright_Denis_Olivier_1996_-_All_rights_reserved.\n");
  65.   fprintf(File,"WINDOW: 180 190\n");
  66.   fprintf(File,"TEXTZONE: 75  40 Nb_vertices 4 Vertices_around_the_gateway\n");
  67.   fprintf(File,"TEXTZONE: 75  60 Radius 1.0 gateway's radius\n");
  68.   fprintf(File,"TEXTZONE: 75  80 Cyl_Radius 0.01 Cylinder's_radius_for_connection\n");
  69.   fprintf(File,"TEXTZONE: 75 100 Offset 0.15 Offset_for_next_cylinder\n");
  70.   fprintf(File,"TEXTZONE: 75 120 Nb_rotations 8 Nb_of_polygon_rotations\n");
  71.   fprintf(File,"END:\n");
  72.  
  73.   fclose(File);
  74.   return 1;
  75. }
  76.  
  77. // ---------------------------------------------------------------------------
  78. // -- COMPUTE THE SX,RX,TX OF A CYLINDER WITH JUST 2 POINTS ------------------
  79. // ---------------------------------------------------------------------------
  80. CYL calcul_cylinder(double X1,double Y1,double X2,double Y2) {
  81.   CYL C;
  82.  
  83.   C.Long=sqrt((X1-X2)*(X1-X2)+(Y1-Y2)*(Y1-Y2))/2;
  84.   C.Angle=90+atan2((Y1-Y2),(X1-X2))*(180/PI);
  85.   C.X=(X1+X2)/2;
  86.   C.Y=(Y1+Y2)/2;
  87.  
  88.   return C;
  89. }
  90.  
  91. // ---------------------------------------------------------------------------
  92. // -- MAIN PROGRAM -----------------------------------------------------------
  93. // ---------------------------------------------------------------------------
  94. void main (int argc,char *argv[]) {
  95.   FILE *File;
  96.   int Nb=1000; // ----- Start at object nb 1000 (why, I dunno !)
  97.   char NomLogiciel[]={"GATEWAY"};
  98.   char VerLogiciel[]={"1.0"};
  99.   union REGS regs;
  100.   VECTOR VP,VS,VR,VT;
  101.   char Buffer[20];
  102.   
  103.   double R=1.0;
  104.   double N=4;
  105.   int i,j;
  106.   double T;
  107.   double X1,X0,Y1,Y0;
  108.   double E=0.01,D=.15,P=8;
  109.   CYL C;
  110.  
  111.   // ----------- The command line parameter /ASK tell the program
  112.   // ----------- to put out the graphic data script for the
  113.   // ----------- interface under POVLAB.
  114.  
  115.   if (argc>1) {
  116.     if (strcmp(strupr(argv[1]),"/ASK")==NULL) {
  117.       out_data_interface();
  118.       exit(0);
  119.     }
  120.   } else {
  121.     exit(0);
  122.   }
  123.  
  124.   // -------------- Don't clear the screen if you dont want, there's
  125.   // -------------- not reason except to display some
  126.   // -------------- Informations about the work it's doing.
  127.   // -------------- Put your copyright infos here
  128.  
  129.   /*
  130.   #if __WATCOMC__
  131.     regs.w.ax=3;
  132.   #else
  133.     regs.x.ax=3;
  134.   #endif
  135.   int86(0x10,®s,®s); // Textmode with int 10H
  136.  
  137.   puts("");
  138.   printf("%s release %s, (C) Copyright ChromaGraphics, 1994-1995.\n",NomLogiciel,VerLogiciel);
  139.   printf("External process for POVLAB - Generate a grid of objects.\n");
  140.   printf("All rights reserved, (R) Denis Olivier - %s.\n",__DATE__);
  141.   puts("");
  142.   */
  143.  
  144.   // ------------- Don't forget to name the .INC like the .EXE
  145.   // ------------- file you're running :) !
  146.   // ------------- Here follow the code for your own process :
  147.   // ------------- Coding what you want to do with the object.
  148.  
  149.   File=fopen("GATEWAY.INC","w+t");
  150.  
  151.   N=atof(argv[1]);
  152.   R=atof(argv[2]);
  153.   E=atof(argv[3]);
  154.   D=atof(argv[4]);
  155.   P=atof(argv[5]);
  156.  
  157.   X0=1.0;
  158.   Y0=0.00000001;
  159.   X1=Y1=0.0;
  160.   T=2*PI/N;
  161.  
  162.   for (j=1;j<=(int) P;j++) {
  163.     for (i=1;i<=(int) P;i++) {
  164.       X1= X0*R*cos(T)+Y0*R*sin(T);
  165.       Y1=-X0*R*sin(T)+Y0*R*cos(T);
  166.       C=calcul_cylinder(X0,Y0,X1,Y1);
  167.  
  168.       if (i!=P) {
  169.         X0=X1;
  170.         Y0=Y1;
  171.       }
  172.  
  173.       // ------------------------ Prepare the datas
  174.  
  175.       make_vector(VP,0,0,0);
  176.       make_vector(VS,(double)   E,(double) C.Long,(double)       E);
  177.       make_vector(VR,           0,              0,(double) C.Angle);
  178.       make_vector(VT,(double) C.X,(double)   -C.Y,               0);
  179.       sprintf(Buffer,"CYL%04d",Nb);
  180.  
  181.       // ------------------------ Here's the part to write the file
  182.  
  183.       write_object(File,Nb,CYLINDRE,VP,VS,VR,VT,7,"Default",0,0,Buffer);
  184.  
  185.       Nb=Nb+1;
  186.  
  187.       if ((kbhit()) && getch()==27) {
  188.         fclose(File);
  189.         remove("GATEWAY.INC");
  190.         exit(0);
  191.       }
  192.  
  193.       // ----------------------------------------------------------
  194.     }
  195.  
  196.     X0=X0+(D*(X1-X0));
  197.     Y0=Y0+(D*(Y1-Y0));
  198.   }
  199.  
  200.   fclose(File);
  201. }
  202.  
  203.